/*
 * Created on 17-ene-2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package hotel.ejb;

import hotel.interfaces.*;

import java.rmi.RemoteException;
import java.util.Collection;
import java.util.Iterator;
import java.util.Vector;

import javax.ejb.EJBException;
import javax.ejb.*;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;

import javax.ejb.CreateException;

/**
 * @ejb.bean name="HabitacioFacade"
 *           display-name="Name for HabitacioFacade"
 *           description="Description for HabitacioFacade"
 *           jndi-name="ejb/HabitacioFacade"
 *           type="Stateless"
 *           view-type="both"
 * 
 * @ejb.util generate="physical"
 */
public class HabitacioFacadeBean implements SessionBean {

	HabitacioLocalHome habitacioHome = null;
	/**
	 * 
	 */
	public HabitacioFacadeBean() {
		super();
		// TODO Auto-generated constructor stub
	}

	/* (non-Javadoc)
	 * @see javax.ejb.SessionBean#ejbActivate()
	 */
	public void ejbActivate() throws EJBException, RemoteException {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see javax.ejb.SessionBean#ejbPassivate()
	 */
	public void ejbPassivate() throws EJBException, RemoteException {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see javax.ejb.SessionBean#ejbRemove()
	 */
	public void ejbRemove() throws EJBException, RemoteException {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext)
	 */
	public void setSessionContext(SessionContext ctx)
		throws EJBException,
		RemoteException {
		// TODO Auto-generated method stub

	}

	/**
	 * Default create method
	 * 
	 * @throws CreateException
	 * @ejb.create-method
	 */
	public void ejbCreate() throws CreateException {
		// TODO Auto-generated method stub
		try {
			habitacioHome = HabitacioUtil.getLocalHome();
		} catch (Exception e) {
			throw new CreateException(e.getMessage());
		}
	}
	
	/**
	 * Business method
	 * @ejb.interface-method  view-type = "both"
	 */
	public void setTipus(Integer ID, Integer tipus) throws FinderException {
		// TODO Auto-generated method stub
		HabitacioLocal h = habitacioHome.findByPrimaryKey(new HabitacioPK(ID));
		h.setTipus(tipus);
	}
	
	/**
	 * Business method
	 * @ejb.interface-method  view-type = "both"
	 */
	public Integer getTipus(Integer ID) throws FinderException {
		// TODO Auto-generated method stub
		HabitacioLocal h = habitacioHome.findByPrimaryKey(new HabitacioPK(ID));
		return h.getTipus();
	}
	
	/**
	 * Business method
	 * @ejb.interface-method  view-type = "both"
	 */
	public void habilitar(Integer ID, Integer tipus) throws CreateException {
		// TODO Auto-generated method stub
		HabitacioValue h = new HabitacioValue();
		h.setID(ID);
		h.setTipus(tipus);
		habitacioHome.create(h);
	}
	
	/**
	 * Business method
	 * @ejb.interface-method  view-type = "both"
	 */
	public void deshabilitar(Integer ID) throws FinderException, RemoveException {
		// TODO Auto-generated method stub
		HabitacioLocal h = habitacioHome.findByPrimaryKey(new HabitacioPK(ID));
		h.remove();
	}
	
	/**
	 * Business method
	 * @ejb.interface-method  view-type = "both"
	 */
	public Collection llistat() throws FinderException {
		// TODO Auto-generated method stub
		Collection llistat = new Vector();
		
		Collection c = habitacioHome.findAll();
		Iterator it = c.iterator();
		while(it.hasNext()) {
			HabitacioLocal habitacio = (HabitacioLocal)it.next();
			// Llistat de ClientValue
			HabitacioValue vHabitacio = new HabitacioValue();
			vHabitacio.setID(habitacio.getID());
			vHabitacio.setTipus(habitacio.getTipus());
			llistat.add(vHabitacio);
		}
		return llistat;
	}

}